package com.gitee.shigen.es.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.*;

import com.gitee.shigen.common.msg.Result;
import com.gitee.shigen.es.service.IndexObjectService;
import com.gitee.shigen.es.vo.IndexObject;
import com.gitee.shigen.es.vo.QueryVo;

import cn.easyes.core.biz.PageInfo;

/**
 * @author shigenfu
 * @date 2023/5/1 1:10 下午
 */
@RestController
@RequestMapping(value = "search")
public class IndexController {

    @Resource
    private IndexObjectService indexObjectService;

    @PostMapping()
    public Result<PageInfo<IndexObject>> page(@RequestBody QueryVo queryVo) {
        PageInfo<IndexObject> page = indexObjectService.page(queryVo.getKeyword(), queryVo.getPageNum(), queryVo.getPageSize());
        return Result.success(page);
    }

    @PostMapping(value = "index")
    public Result<Integer> saveBatch(@RequestBody List<IndexObject> indexObjects) {
        int count = indexObjectService.insertBatch(indexObjects);
        return Result.success(count);
    }

    @PutMapping(value = "index")
    public Result<Integer> update(@RequestBody IndexObject indexObject) {
        int count = indexObjectService.update(indexObject);
        return Result.success(count);
    }

    @DeleteMapping(value = "index/{id}")
    public Result<Integer> deleteById(@PathVariable("id") Long id) {
        int count = indexObjectService.deleteById(id);
        return Result.success(count);
    }
}
